package registnet.records;

import java.util.List;
import java.util.ListIterator;
import java.util.Vector;

public class Curriculum {

	private String curriculumCode;
	private String curriculumName;
	private DegreeProgram degreeProgram;
	private List<CurriculumCourse> courses = new Vector<CurriculumCourse>();
	
	
	/**
	 * Default constructor
	 */
	public Curriculum(){}
	
	
	/**
	 * Constructs a curriculum with an assigned curriculum code
	 * 
	 * @param curriculumCode - The code assigned to the curriculum
	 */
	public Curriculum(String curriculumCode){
		this.curriculumCode = curriculumCode;
	}

	
	/**
	 * Gets the code assigned to the curriculum
	 * 
	 * @return 	The code assigned to the curriculum
	 */
	public String getCurriculumCode() {
		return curriculumCode;
	}

	
	/**
	 * Sets the code assigned to the curriculum
	 * 
	 * @param curriculumCode - The code assigned to the curriculum
	 */
	public void setCurriculumCode(String curriculumCode) {
		this.curriculumCode = curriculumCode;
	}

	
	/**
	 * Gets the name of the curriculum
	 * 
	 * @return 	The name of the curriculum
	 */
	public String getCurriculumName() {
		return curriculumName;
	}

	
	/**
	 * Sets the name of the curriculum
	 * 
	 * @param curriculumName - The name of the curriculum
	 */
	public void setCurriculumName(String curriculumName) {
		this.curriculumName = curriculumName;
	}

	
	/**
	 * Gets the degree program that makes use of the curriculum
	 * 
	 * @return 	The degree program that makes use of the curriculum
	 */
	public DegreeProgram getDegreeProgram() {
		return degreeProgram;
	}

	
	/**
	 * Sets the degree program that makes use of the curriculum
	 * 
	 * @param degreeProgram - The degree program that makes use of the curriculum
	 */
	public void setDegreeProgram(DegreeProgram degreeProgram) {
		this.degreeProgram = degreeProgram;
	}
	
	
	/**
	 * Gets the courses included in the curriculum
	 * 
	 * @return	The courses included in the curriculum
	 */
	public List<CurriculumCourse> getCourses(){
		return this.courses;
	}
	
	
	/**
	 * Sets the courses included in the curriculum
	 * 
	 * @param courses - The courses to include in the curriculum
	 */
	public void setCourses(List<CurriculumCourse> courses){
		this.courses = courses;
	}
	
	
	/**
	 * Adds the course into the curriculum
	 * 
	 * @param course
	 */
	public void addCourse(CurriculumCourse course){
		this.courses.add(course);
	}
	
	/**
	 * Gets the courses which the students need to take 
	 * 
	 * @param semester - The semester
	 * @param year - The year level
	 * @return
	 */
	public List<CurriculumCourse> getCourses(int semester, int year) {
		List<CurriculumCourse> retval = new Vector<CurriculumCourse>();
		ListIterator<CurriculumCourse> li = courses.listIterator();
		while(li.hasNext()){
			CurriculumCourse tmpCourse = li.next();
			if(year==tmpCourse.getYear() && semester==tmpCourse.getSemester())
				retval.add(tmpCourse);
		}
		return retval;
	}
	
	
	/**
	 * Gets the courses which the students need to take
	 * 
	 * @param year - The year level
	 * @return
	 */
	public List<CurriculumCourse> getCourses(int year) {
		List<CurriculumCourse> retval = new Vector<CurriculumCourse>();
		ListIterator<CurriculumCourse> li = courses.listIterator();
		while(li.hasNext()){
			CurriculumCourse tmpCourse = li.next();
			if(year==tmpCourse.getYear())
				retval.add(tmpCourse);
		}
		return retval;
	}
	
	
	/**
	 * Gets the number of units the student has to earn
	 * 
	 * @param semester - The semester
	 * @param year - The year level
	 * @return
	 */
	public int getUnits(int semester, int year) {
		ListIterator<CurriculumCourse> li = this.courses.listIterator();
		int totalUnits = 0;
		while(li.hasNext()){
			CurriculumCourse course = li.next();
			if(course.getCourseCode().contains("PE ") || course.getCourseCode().contains("LTS ") || course.getCourseCode().contains("CWTS ") || course.getCourseCode().contains("ROTC ") || course.getCourseCode().contains("NSTP "))
				continue;
			if(course.getYear() == year && course.getSemester() == semester){
				totalUnits += course.getUnit();
			}
		}
		return totalUnits;
	}
}
